﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BulldogCMS.Core.Storage.DataTypes;

namespace BulldogCMS.Core.Storage.Providers
{
    public class LanguagesTreeProvider : IContentTreeProvider
    {
        public IEnumerable<Node> GetRootNodes(long? nodeID = null)
        {
            foreach (var language in Context.Application.Languages)
            {
                Node node = Node.CreateNode(NodeMode.SingleVersion);
                node.TemplateName = "BulldogCMS.Core.Templates.System.LanguageNodeTemplate";
                node.Name = language.Name;
                node.ContentTreeProvider = this;

                List<BaseDataType> fields = new List<BaseDataType>();
                fields.Add(new TextField() {
                    Name = "LanguageName",
                    Value = language.CultureInfo.Name
                });
                
                fields.Add(new TextField()
                {
                    Name = "DisplayName",
                    Value = language.CultureInfo.DisplayName
                });

                fields.Add(new TextField()
                {
                    Name = "EnglishName",
                    Value = language.CultureInfo.EnglishName
                });

                node.SharedFields = fields;
                yield return node;
            }
        }

        public IEnumerable<Node> GetNodes(Node parentNode)
        {
            return new List<Node>();
        }

        public Node GetNode(string currentProviderPath, string name, long parentNodeID)
        {
            throw new NotImplementedException();
        }

        public void SetParameter(string name, string value)
        {
            throw new NotImplementedException();
        }

        public NodeVersion GetNodeVersion(Node node, string languageIdent, int versionNumber)
        {
            throw new NotImplementedException();
        }

        public Node CreateNewNode(Node node)
        {
            throw new NotImplementedException();
        }

        public Node UpdateNode(Node node)
        {
            throw new NotImplementedException();
        }

        public void DeleteNode(Node node)
        {
            throw new NotImplementedException("Deleting is not supported");
        }

        public NodeVersion CreateNewVersion(Node node, NodeVersion newVersion)
        {
            throw new NotImplementedException("Versions not supported");
        }

        public NodeVersion UpdateVersion(Node node, NodeVersion updatedVersion)
        {
            throw new NotImplementedException();
        }

        public NodeVersion DeleteVersion(Node node, NodeVersion versionToBeDeleted)
        {
            throw new NotImplementedException();
        }

        public bool ReadOnly
        {
            get { return true; }
        }
    }
}